#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>\
#include<stdlib.h>
//#include<malloc.h>

 //Definition for singly-linked list.
 struct ListNode {
     int val;
     struct ListNode *next;
 };
 

typedef struct ListNode* SL;
struct ListNode* removeElements(struct ListNode* head, int val) {
    SL dummy = (SL)malloc(sizeof(struct ListNode));
    dummy->next = head;

    SL prev = dummy;
    SL current = head;
    while (current != NULL)
    {
        if (current->val == val)
        {
            prev->next = current->next;
            free(current);
            current = prev->next;
        }
        else
        {
            prev = current;
            current = current->next;
        }
    }
    return dummy->next;
}